package com.renwei.yunlong.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.renwei.yunlong.R;
import com.zyf.fwms.commonlibrary.utils.AutoUtils;

/**
 * 工单 记录 adapter
 *
 * Created by Administrator on 2017/9/11.
 */

public class WorkRecordingPagerAdapter extends RecyclerView.Adapter<WorkRecordingPagerAdapter.WorkRecordingPagerViewHolder>{

    private Context context;
    private LayoutInflater inflater;

    private String[] title = {"张三","李四"};

    private static final int TYPE_TOP = 0x0000;
    private static final int TYPE_NORMAL= 0x0001;

    public WorkRecordingPagerAdapter(Context context){
        this.context = context;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public WorkRecordingPagerViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = inflater.inflate(R.layout.item_spare_application_process,null);
        AutoUtils.auto(view);
        return new WorkRecordingPagerViewHolder(view);
    }

    @Override
    public void onBindViewHolder(WorkRecordingPagerViewHolder holder, int position) {

        if (getItemViewType(position) == TYPE_TOP) {
            holder.ivView.setImageResource(R.mipmap.dot_cur);
            holder.tvName.setText(title[position]);
            holder.tvType.setText("转回");
            holder.textOpinion.setText("意见:");
            holder.tvOpinion.setText("有点问题，所以转回给你");
            holder.tvDate.setText("2017/10/10");
            holder.tvTime.setText("10:10");
        }else if (getItemViewType(position) == TYPE_NORMAL) {
            holder.ivView.setImageResource(R.mipmap.dot);
            holder.tvName.setText(title[position]);
            holder.tvType.setText("转回");
            holder.textOpinion.setText("意见:");
            holder.tvOpinion.setText("有点问题，所以转回给你");
            holder.tvDate.setText("2017/10/10");
            holder.tvTime.setText("10:10");
        }
    }

    @Override
    public int getItemCount() {
        return title.length;
    }

    @Override
    public int getItemViewType(int position) {
        if (position == 0) {
            return TYPE_TOP;
        }
        return TYPE_NORMAL;
    }

    static class WorkRecordingPagerViewHolder extends RecyclerView.ViewHolder{

        private View itemView;
        private ImageView ivView;
        private TextView tvName;
        private TextView tvType;
        private TextView textOpinion;
        private TextView tvOpinion;//意见
        private TextView tvDate;//日期
        private TextView tvTime;//时间

        public WorkRecordingPagerViewHolder(View view) {
            super(view);
            itemView = view;
            ivView = (ImageView) itemView.findViewById(R.id.iv_view);
            tvName = (TextView) itemView.findViewById(R.id.tv_name);
            tvType = (TextView) itemView.findViewById(R.id.tv_type);
            textOpinion = (TextView) itemView.findViewById(R.id.text_opinion);
            tvOpinion = (TextView) itemView.findViewById(R.id.tv_opinion);
            tvDate = (TextView) itemView.findViewById(R.id.tv_date);
            tvTime = (TextView) itemView.findViewById(R.id.tv_time);
        }
    }
}
